package com.haima.ziliao.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.haima.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haima.common.annotation.Log;
import com.haima.common.core.controller.BaseController;
import com.haima.common.core.domain.AjaxResult;
import com.haima.common.enums.BusinessType;
import com.haima.ziliao.domain.PZizhi;
import com.haima.ziliao.service.IPZizhiService;
import com.haima.common.utils.poi.ExcelUtil;
import com.haima.common.core.page.TableDataInfo;

/**
 * 资质证书Controller
 * 
 * @author hima
 * @date 2024-12-10
 */
@RestController
@RequestMapping("/ziliao/zizhi")
public class PZizhiController extends BaseController
{
    @Autowired
    private IPZizhiService pZizhiService;

    /**
     * 查询资质证书列表
     */
    @PreAuthorize("@ss.hasPermi('ziliao:zizhi:list')")
    @GetMapping("/list")
    public TableDataInfo list(PZizhi pZizhi)
    {
        startPage();
        List<PZizhi> list = pZizhiService.selectPZizhiList(pZizhi);
        return getDataTable(list);
    }

    @GetMapping("/zizhilist")
    public AjaxResult zizhilist(PZizhi pZizhi)
    {
        pZizhi.setUid(SecurityUtils.getUserId());
        List<PZizhi> list = pZizhiService.selectPZizhiList(pZizhi);
        return AjaxResult.success(list);
    }

    @GetMapping("/zizhilistByTid")
    public AjaxResult zizhilist(Long tid)
    {
        PZizhi pZizhi = new PZizhi();
        pZizhi.setTid(tid);
        List<PZizhi> list = pZizhiService.selectPZizhiList(pZizhi);
        return AjaxResult.success(list);
    }

    @GetMapping("/addZizhi")
    public AjaxResult addZizhi(PZizhi pZizhi)
    {
        pZizhi.setUid(SecurityUtils.getUserId());
        pZizhiService.insertPZizhi(pZizhi);
        return AjaxResult.success();
    }

    @GetMapping("/editZizhi")
    public AjaxResult editZizhi(PZizhi pZizhi)
    {
        PZizhi zz = pZizhiService.selectPZizhiById(pZizhi.getId());
        zz.setName(pZizhi.getName());
        zz.setPic(pZizhi.getPic());
        pZizhiService.updatePZizhi(zz);
        return AjaxResult.success();
    }

    @GetMapping("/delZizhi")
    public AjaxResult delZizhi(PZizhi pZizhi)
    {
        pZizhiService.deletePZizhiById(pZizhi.getId());
        return AjaxResult.success();
    }

    /**
     * 导出资质证书列表
     */
    @PreAuthorize("@ss.hasPermi('ziliao:zizhi:export')")
    @Log(title = "资质证书", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PZizhi pZizhi)
    {
        List<PZizhi> list = pZizhiService.selectPZizhiList(pZizhi);
        ExcelUtil<PZizhi> util = new ExcelUtil<PZizhi>(PZizhi.class);
        util.exportExcel(response, list, "资质证书数据");
    }

    /**
     * 获取资质证书详细信息
     */
    @PreAuthorize("@ss.hasPermi('ziliao:zizhi:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pZizhiService.selectPZizhiById(id));
    }

    /**
     * 新增资质证书
     */
    @PreAuthorize("@ss.hasPermi('ziliao:zizhi:add')")
    @Log(title = "资质证书", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PZizhi pZizhi)
    {
        return toAjax(pZizhiService.insertPZizhi(pZizhi));
    }

    /**
     * 修改资质证书
     */
    @PreAuthorize("@ss.hasPermi('ziliao:zizhi:edit')")
    @Log(title = "资质证书", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PZizhi pZizhi)
    {
        return toAjax(pZizhiService.updatePZizhi(pZizhi));
    }

    /**
     * 删除资质证书
     */
    @PreAuthorize("@ss.hasPermi('ziliao:zizhi:remove')")
    @Log(title = "资质证书", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pZizhiService.deletePZizhiByIds(ids));
    }
}
